package com.awesome.designpatterndemo.prototype.prototype2;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import com.awesome.designpatterndemo.R;

public class Prototype2Activity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_prototype2);

        WorkDocument originDoc = new WorkDocument();
        originDoc.setText("这是一篇文档");
        originDoc.addImage("图片1");
        originDoc.addImage("图片2");
        originDoc.addImage("图片3");
        originDoc.showDocument();

        WorkDocument doc2 =  originDoc.clone();
        doc2.showDocument();
        // 修改文档副本
        doc2.setText("这是修改后的doc2文本");
        doc2.addImage("哈哈.jpg");
        doc2.showDocument();

        originDoc.showDocument();

        // 执行结果，源文件没有被修改
        // 结论，引用类型需要单独拷贝，这种是深拷贝
    }
}